/*
 *  Copyright 2009 Lucas Nazário dos Santos
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package net.sourceforge.retriever.sample;

import java.net.URL;
import java.util.Map;

import net.sourceforge.retriever.Retriever;
import net.sourceforge.retriever.analyzer.Analyzer;
import net.sourceforge.retriever.fetcher.Resource;

/*
 * This sample shows the minimum amount of configuration needed to run the crawler.
 */
public class GettingStarted {


	public static void main(final String[] args) throws Exception {

		final Retriever crawler = new Retriever();

		// Initialize it with a bunch of seeds
		crawler.addSeed(new URL("http://www.yahoo.com/"));
		crawler.addSeed(new URL("http://www.google.com/"));
		crawler.addSeed(new URL("http://www.uol.com/"));

		// At each crawled resource, its URL is printed
		crawler.setAnalyzer(new Analyzer() {
			private int i = 0;
			public void analyze(final Resource resource, final Map<String, Object> additionalInfo) {
				System.out.println(++i + " " + resource.getURL().toExternalForm());
			}
		});

		// Notice that, once started, the crawler will go through all the web, since 
		// any restriction was made using the crawler's setFilter(Filter) method.
		crawler.start();
	}
}